home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 3 code / ISO 9660 & High Sierra / iso9660 ƒ / mydialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-04  |  4.5 KB  |  211 lines  |  [TEXT/KAHL]

  1. /************************************************************************
  2.  *
  3.  *    Copyright © 1990    Apple Computer, Inc.  All rights reserved.
  4.  *
  5.  ************************************************************************/
  6.  
  7. #include <DialogMgr.h>
  8. #include <WindowMgr.h>
  9. #include <fontmgr.h>
  10. #include <pascal.h>
  11. #include <stdio.h>
  12.  
  13. #include "mydialog.h"
  14. #include "textdlog.h"
  15. #include "DialogUtils.h"
  16.  
  17. #define    VOLNAME_DIALOG        256
  18. #define    DESTROY_DIALOG        257
  19. #define FirstButton            1
  20. #define SecondButton        2
  21. #define StringField            3
  22.  
  23. extern void strcpy(char *, char *);
  24.  
  25.  
  26. /************************************************************************
  27.  *
  28.  *  Function:        strcpy
  29.  *
  30.  *  Purpose:        copy a string
  31.  *
  32.  *  Returns:        nothing
  33.  *
  34.  *  Side Effects:    copies *src into *dst
  35.  *
  36.  *  Description:    loop copying until we hit the null byte of src.
  37.  *                    we assume dst is larger than or equal to src in
  38.  *                    size, or major damage occurs.
  39.  *
  40.  ************************************************************************/
  41. static void
  42. strcpy(dst, src)
  43. char *dst;
  44. char *src;
  45. {
  46.     while (*dst++ = *src++);
  47. }
  48.  
  49. /************************************************************************
  50.  *
  51.  *  Function:        AskForString
  52.  *
  53.  *  Purpose:        ask the user for a string.
  54.  *
  55.  *  Returns:        Boolean
  56.  *                        true if the user entered something
  57.  *                        false if the user asked to cancel out
  58.  *
  59.  *  Side Effects:
  60.  *                    theString is filled with a C string if we return true.
  61.  *
  62.  *  Description:
  63.  *                    put up a dialog.
  64.  *
  65.  ************************************************************************/
  66. Boolean
  67. AskForString(prompt, theString)
  68. char    *prompt;
  69. char    *theString;
  70. {
  71.     DialogPtr        dPtr;
  72.     short            result;
  73.     WindowPtr        wPtr;
  74.     
  75.     short            unusedType;    /* for hiliting okay button */
  76.     Handle            hItem;
  77.     Rect            dBox;
  78.     
  79.     Boolean            leaveYet;
  80.     
  81.     Str255            enteredString;
  82.  
  83.     dPtr = GetNewDialog(DU_CenterDLOG(VOLNAME_DIALOG), (DialogPeek)0L, (WindowPtr)-1);
  84.     
  85.     HighLightDefault(dPtr);                /* hilite OK button */
  86.     
  87.     SelIText(dPtr, StringField, 0, 999); /* all of the string field selected */
  88.  
  89.     ParamText((StringPtr)prompt, NULL, NULL, NULL);
  90.     
  91.     leaveYet = false;
  92.     do
  93.     {
  94.         HighLightDefault(dPtr);
  95.         ModalDialog(0, &result);
  96.         if (result == FirstButton) 
  97.             leaveYet = true;
  98.         if (result == SecondButton)
  99.         {
  100.             SysBeep(1);
  101.             leaveYet = true;
  102.             return false;
  103.         }
  104.     } while (leaveYet == false);
  105.     
  106.  
  107.     GetDItem(dPtr, StringField, &unusedType, &hItem, &dBox);
  108.     GetIText(hItem, (StringPtr)&enteredString);
  109.     strcpy(theString, PtoCstr((char *)&enteredString));
  110.     DisposDialog(dPtr);
  111.     return true;
  112. }
  113.  
  114. /************************************************************************
  115.  *
  116.  *  Function:        AskDestroyDisk
  117.  *
  118.  *  Purpose:        Check that you really want to nuke a disk
  119.  *
  120.  *  Returns:        Boolean
  121.  *                    true = yes, destroy it
  122.  *                    false = no, leave it alone, it was a mistake.
  123.  *
  124.  *  Side Effects:    none.
  125.  *
  126.  *  Description:    display our warning about destroying a disk.
  127.  *                    Ask, using a modal dialog, whether the user really
  128.  *                    wants to lose it.  (Default button is cancel, since
  129.  *                    this is such a permanent thing...)
  130.  *
  131.  *
  132.  ************************************************************************/
  133. Boolean
  134. AskDestroyDisk(driveNumber)
  135. short    driveNumber;
  136. {
  137.     DialogPtr        dPtr;
  138.     short            result;
  139.     short            unusedType;    /* for hiliting okay button */    
  140.     Boolean            leaveYet;
  141.     Boolean            okayToDestroy;
  142.     
  143.     Str255            volumeName;
  144.     short            vRefNum;
  145.     long            freeBytes;
  146.  
  147.     okayToDestroy = true;
  148.     dPtr = GetNewDialog(DU_CenterDLOG(DESTROY_DIALOG), (DialogPeek)0L, (WindowPtr)-1);
  149.  
  150.     HighLightDefault(dPtr);
  151.     
  152.     if (GetVInfo(driveNumber, volumeName, &vRefNum, &freeBytes) != noErr)
  153.         okayToDestroy = false;
  154.     
  155.     if (okayToDestroy)
  156.     {
  157.         ParamText((StringPtr)volumeName, NULL, NULL, NULL);
  158.         
  159.         leaveYet = false;
  160.         do
  161.         {
  162.             HighLightDefault(dPtr);
  163.             ModalDialog(0, &result);
  164.             if (result == SecondButton) 
  165.                 leaveYet = true;
  166.             if (result == FirstButton)
  167.             {
  168.                 SysBeep(1);
  169.                 leaveYet = true;
  170.                 okayToDestroy = false;
  171.             }
  172.         } while (leaveYet == false);
  173.     }
  174.  
  175.     DisposDialog(dPtr);
  176.     return okayToDestroy;
  177. }
  178.  
  179.  
  180.  
  181. /************************************************************************
  182.  *
  183.  *  Function:        Help
  184.  *
  185.  *  Purpose:        explain what we're doing
  186.  *
  187.  *  Returns:        void
  188.  *
  189.  *  Side Effects:    none.
  190.  *
  191.  *  Description:    display our help text.  Currently always returns true.
  192.  *
  193.  *
  194.  ************************************************************************/
  195. Boolean
  196. Help()
  197. {
  198.     Handle    tHandle;
  199.         
  200.     tHandle = GetResource('TEXT', 1001);
  201.     if (tHandle != (Handle)0)
  202.     {
  203.         HLock(tHandle);
  204.         TextDialog(1001, tHandle, times, 12, true);
  205.         HUnlock(tHandle);
  206.         ReleaseResource(tHandle);
  207.     }
  208.     return true;
  209. }
  210.  
  211.